const electron = window.require('electron')

const throttle=(delay,callback)=>{
    let startTime = new Date().getTime();
    let timer = null;
    return function (params) {
        const currentTime = new Date().getTime();
        clearTimeout(timer)
        //console.log("时间差：", currentTime - startTime);
        if (currentTime - startTime >= delay) {
            callback(params);
            startTime = currentTime;
        } else {
            timer = setTimeout(function () {
                callback(params);
            }, delay)
        }
    }
}

const callback=throttle(15,({x,y})=>{
    electron.ipcRenderer.send('move-application',{x,y});
})

const appMove=(x,y)=>{
    callback({x,y});
}

const close=()=>{
    electron.ipcRenderer.send('close');
}
const fullScreen=()=>{
    electron.ipcRenderer.send('fullScreen');
}
const minimize=()=>{
    electron.ipcRenderer.send('minimize');
}

export default {
    close,
    fullScreen,
    minimize,
    appMove
}
